﻿
using System.Collections.Generic;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using HuaCheng.DataAccess;
namespace HuaCheng.Controller
{
    public class DeviceLogControl
    {
        /// <summary>
        /// 根据数据库中log_mid表中的记录生成设备日志中的treelist
        /// </summary>
        /// <param name="deviceLog"></param>
        /// <param name="treeList"></param>
        /// <returns></returns>
        public static TreeList SetTreeListByDeviceLogList(TreeList treeList,int unit_id,int chl_id)
        {
            treeList.ClearNodes();
            int test_id = StepHelper.GetTestIdById(IndexPage.devIp, unit_id, chl_id);
            List<DeviceLog> deviceLogList = DeviceLogHelper.RetrieveDeviceLog(unit_id, chl_id,test_id);
            //遍历设备日志列表
            for (int i = 0; i < deviceLogList.Count; i++)
            {
                DeviceLog deviceLog = deviceLogList[i];
                treeList = SetTreeListNodeByDeviceLog(deviceLog, treeList, i);
            }
            return treeList;
        }
        /// <summary>
        /// 根据DeviceLog对象生成TreeList节点
        /// </summary>
        /// <param name="deviceLog"></param>
        /// <param name="treeList"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        public static TreeList SetTreeListNodeByDeviceLog(DeviceLog deviceLog, TreeList treeList, int i)
        {
            //新增节点
            TreeListNode tmpNode = treeList.Nodes.Add();
            tmpNode["SerialNum"] = treeList.Nodes.Count;
            string secColumn = deviceLog.DevIp + "-" + deviceLog.UnitId + "-" + deviceLog.ChlId;
            tmpNode["DeUnCh"] = secColumn;
            tmpNode["DateTime"] = deviceLog.TestATime;
            tmpNode["DeviceEvent"] = deviceLog.WorkType;
            treeList.SetNodeIndex(tmpNode, i);
            return treeList;
        }
    }
}
